package com.agriculture.monitor.controller;


import com.agriculture.monitor.base.ResultInfo;
import com.agriculture.monitor.dto.MenuDataDTO;
import com.agriculture.monitor.dto.RoleMenuDTO;
import com.agriculture.monitor.entity.Menu;
import com.agriculture.monitor.service.IMenuService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author admin
 * @since 2024-03-21
 */
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    IMenuService menuService;


    @ApiOperation(value = "查询菜单树", notes = "查询菜单树")
    @PostMapping("/tree")
    public ResultInfo<List<Menu>> tree(@RequestBody Menu menu) {
        return ResultInfo.OK(menuService.tree(menu));
    }

    @ApiOperation(value = "查询", notes = "查询")
    @GetMapping("/checkRole")
    public ResultInfo<MenuDataDTO> checkRole(@RequestParam(value = "roleId", required = false) Integer roleId) {
        return ResultInfo.OK(menuService.checkRole(roleId));
    }

    @ApiOperation(value = "保存角色权限", notes = "保存角色权限")
    @PostMapping("/saveRoleMenu")
    public ResultInfo<Boolean> saveRoleMenu(@RequestBody RoleMenuDTO roleMenuDTO) {
        return ResultInfo.OK(menuService.saveRoleMenu(roleMenuDTO));
    }
}
